//
//  QGRegistViewController.h
//  qeegooCQGt
//
//  Created by heew on 16/1/7.
//  Copyright © 2016年 com.autozi. All rights reserved.
//

#import "QGRegistInputTextCell.h"

@interface QGRegistInputTextCell ()<UITextFieldDelegate>

@property (nonatomic,strong)UILabel *tagLabel;

@property (nonatomic,strong)UIImageView *tagSeprateLine;

@property (nonatomic,strong)UIImageView *topLine;

@property (nonatomic,strong)UIImageView *bottomLine;

@property (nonatomic,strong)UITextField *inputTextField;

@property (nonatomic,strong)UIView *stateView;

@end
@implementation QGRegistInputTextCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = QGMainBackgroundColor;
        
        self.stateView = [[UIView alloc]init];
        self.stateView.backgroundColor = [UIColor whiteColor];
        self.stateView.userInteractionEnabled = YES;
        [self.contentView addSubview:self.stateView];
        
        self.topLine = [[UIImageView alloc]init];
        self.topLine.backgroundColor = QGMainBackgroundColor;
        self.topLine.viewWidth = SCREEN_WIDTH;
        self.topLine.viewHeight = 0.5f;
        [self.contentView addSubview:self.topLine];
        
        self.tagLabel = [[UILabel alloc]init];
        self.tagLabel.font = QGListTitleAndDetailTextFont;
        self.tagLabel.textColor = QGMainThemeColor;
        [self.contentView addSubview:self.tagLabel];
        
        self.tagSeprateLine = [[UIImageView alloc]init];
        self.tagSeprateLine.viewWidth = 0.5f;
        self.tagSeprateLine.viewHeight = 30.f;
        self.tagSeprateLine.backgroundColor = QGMainSeprateLineColor;
        [self.contentView addSubview:self.tagSeprateLine];
        
        self.inputTextField = [[UITextField alloc]init];
        self.inputTextField.font = QGListTitleAndDetailTextFont;
        self.inputTextField.textColor = QGListTitleAndDetailTextColor;
        self.inputTextField.delegate = self;
        [self.contentView addSubview:self.inputTextField];
        
        self.bottomLine = [[UIImageView alloc]init];
        self.bottomLine.backgroundColor = QGMainSeprateLineColor;
        self.bottomLine.viewWidth = SCREEN_WIDTH;
        self.bottomLine.viewHeight = 0.5f;
        [self.contentView addSubview:self.bottomLine];
        
        [QGNotificationCenter addObserver:self selector:@selector(observeTextCQGnged:) name:UITextFieldTextDidChangeNotification object:nil];
    }
    return self;
}

- (void)dealloc
{
    [QGNotificationCenter removeObserver:self];
}

- (void)setContentModel:(QGRegistContentModel *)contentModel
{
    self.tagLabel.text = contentModel.tagName;
    [self.tagLabel sizeToFit];
    
    CGFloat contentHeight = contentModel.contentHeight - 15.f;
    
    self.tagLabel.viewLeft = 13.f;
    self.tagLabel.viewCenterY = contentHeight/2;
    
    self.tagSeprateLine.viewLeft = self.tagLabel.viewRight + 10.f;
    self.tagSeprateLine.viewHeight = self.tagLabel.viewHeight;
    self.tagSeprateLine.viewCenterY = self.tagLabel.viewCenterY;
    
    self.inputTextField.viewWidth = SCREEN_WIDTH - self.tagSeprateLine.viewRight - 8.f - 13.f;
    self.inputTextField.viewLeft = self.tagSeprateLine.viewRight + 8.f;
    self.inputTextField.viewHeight = contentHeight - 2*4.f;
    self.inputTextField.viewCenterY = contentHeight/2;
    self.inputTextField.placeholder = contentModel.placeHolder;
    self.inputTextField.text = contentModel.content;
    
    self.stateView.viewWidth = SCREEN_WIDTH;
    self.stateView.viewHeight = contentHeight;
    self.bottomLine.viewBottom = contentHeight;
    
}

- (void)observeTextCQGnged:(NSNotification *)noti
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(inputCell:didUpdateContent:)] && ![QGUitility stringIsNull:self.inputTextField.text]) {
        
        [self.delegate inputCell:self didUpdateContent:self.inputTextField.text];
    }
}


@end
